//
//  MyCenterMessageViewController.m
//  ShangPiBao
//
//  Created by chirui on 2017/10/25.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "MyCenterMessageViewController.h"
#import "PublishBuyMessageViewController.h"
#import "PublishSellerMessageViewController.h"
#import "BuyManagerViewController.h"
#import "SellManagerViewController.h"

@interface MyCenterMessageViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
    UITableView * _tableView;
}

@end

@implementation MyCenterMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    TitleView(@"我的消息");

//    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_nav_return" target:self action:@selector(back)];
    
    [self creatTableView];
}

-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)creatTableView {
    
    _tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64) style:UITableViewStyleGrouped];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    
    UIView * view =[[UIView alloc]init];
    _tableView.tableFooterView = view;
    [self.view addSubview:_tableView];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 4;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 50;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSArray * array = @[@"发布求购信息",@"发布供应消息",@"求购信息管理",@"供应信息管理"];
    
    static  NSString * str = @"cellid";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
    
    if (cell==nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }else {
        while ([cell.contentView.subviews lastObject]!=nil) {
            
            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
        }
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = array[indexPath.row];
    cell.textLabel.font =[UIFont systemFontOfSize:15];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row==0) {
//        if ([USER_DEFAULTGet(@"ujd") isEqualToString:@"2"]){
//            
//            SHuiMBhudTextTimeStr(@"您还没权限操作！");
//            
//            return;
//        }
        if ([USER_DEFAULTGet(@"ujd") isEqualToString:@"3"]||[USER_DEFAULTGet(@"ujd") isEqualToString:@"4"]||[USER_DEFAULTGet(@"ujd") isEqualToString:@"2"]){
        
            PublishBuyMessageViewController * buy =[[PublishBuyMessageViewController alloc]init];
            
            [self.navigationController pushViewController:buy animated:YES];
        
        }
        
       
    }else if (indexPath.row==1){
        
    
        
        if ([USER_DEFAULTGet(@"ujd") isEqualToString:@"2"]){
            
            SHuiMBhudTextTimeStr(@"您还没权限操作！");
            
            return;
        }
        if ([USER_DEFAULTGet(@"ujd") isEqualToString:@"3"]||[USER_DEFAULTGet(@"ujd") isEqualToString:@"4"]){
            
            PublishSellerMessageViewController * seller =[[PublishSellerMessageViewController alloc]init];
            [self.navigationController pushViewController:seller animated:YES];
            
        }
    }else if (indexPath.row==2){
        
        BuyManagerViewController * buy =[[BuyManagerViewController alloc]init];
        [self.navigationController pushViewController:buy animated:YES];
    }else if (indexPath.row==3){
        
        SellManagerViewController * buy =[[SellManagerViewController alloc]init];
        [self.navigationController pushViewController:buy animated:YES];
    }

    
}

@end
